import config from '../config'

export default class {
  constructor(data) {
    this.alive = true
    this.attribute = {
      name: data.name,
      hp: {
        current: data.hp,
        max: data.hp
      },
      atk: data.atk,
      def: data.def,
      aspd: data.aspd,
      exp: data.exp,
      gold: data.gold
    }
  }

  get hpPercent() {
    return (this.attribute.hp.current / this.attribute.hp.max) * 100
  }

  updateNextActionTick(tickCount) {
    this.nextActionTick = tickCount + Math.round(this.attribute.aspd / (1000 / config.fps))
  }

  reduceAttributeHp(count) {
    if(this.attribute.hp.current - count <= 0) {
      this.attribute.hp.current = 0
      this.alive = false
    }
    else {
      this.attribute.hp.current -= count
    }
  }
}